package com.example.teamilkmall.controller;

import com.example.teamilkmall.controller.vo.PageVO;
import com.example.teamilkmall.controller.vo.ResultVO;
import com.example.teamilkmall.entity.TeaInfo;
import com.example.teamilkmall.service.TealnfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/tealInfo")
public class TeaInfoController extends BaseController{
    private final TealnfoService tealnfoService;

    public TeaInfoController(TealnfoService tealnfoService) {
        this.tealnfoService = tealnfoService;
    }

    @GetMapping("/listTeaInfo")
    public PageVO<List<TeaInfo>> listTea(Integer limit, Integer page, String name){
        PageInfo<TeaInfo> pageInfo = tealnfoService.listTeainfo(limit, page, name);
        return page(pageInfo.getList(), pageInfo.getTotal());
    }

    @PostMapping("/updateTeaInfo")
    public ResultVO updateTea(TeaInfo teaInfo){
        tealnfoService.updateTea(teaInfo);
        return success();
    }

    @PostMapping("/deloneTeaInfo")
    public ResultVO deloneTea(Integer id){
        tealnfoService.deloneTea(id);
        return success();
    }

    @PostMapping("/addTeaInfo")
    public ResultVO addTea(TeaInfo teaInfo){
        tealnfoService.addTea(teaInfo);
        return success();
    }

    @PostMapping("/listTeaInfoAll")
    public ResultVO<List<TeaInfo>> getTeaList(){
        return success(tealnfoService.listTeainfo());
    }
}
